<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2023/11/4
 * Time: 3:14 PM
 */

namespace app\zyhsweb\controller;

use app\common\cachemodel\ZlcrAstrInfo;
use app\zyhsapi\controller\ZyhsAuth;
use app\zyhsapi\model\ZyhsConsultChatRecordDetails;
use think\Controller;

class Demo extends Controller
{
    /**
     * app全局跳转
     * @return mixed
     */
    public function app_link()
    {
        $headers = $this->request->header();
        $app_type = $headers['app-type'] ?? '';
        try
        {
            $auth = new ZyhsAuth();
            $auth->checkRequestAuth();
            $uid = $auth->user['id'];
        }
        catch (\Exception $e)
        {
            $uid = 0;
        }
        $area = config('consult_zone');
        $astrIds = (new ZlcrAstrInfo())->column('astr_id');
        $astrIdKey = array_rand($astrIds);
        $astrId = $astrIds[$astrIdKey];
        $chatInfo = (new ZyhsConsultChatRecordDetails())->where('uid', $uid)->field('id,astr_id')->find();
        return $this->fetch('app_link', [
            'app_type' => $app_type,
            'version' => $headers['version'] ?? '',
            'area_zone' => $area,
            'astr_id' => $astrId,
            'chat_info' => [
                'astr_id' => $chatInfo ? $chatInfo['astr_id'] : 0,
                'id' => $chatInfo ? $chatInfo['id'] : 0,
            ]
        ]);
    }
}
